class_name HoldGunLaserShooter
extends BaseHoldItem


@onready var ray_cast_2d: RayCast2D = $RayCast2D
@onready var muzzle_in_shape_tester: Area2D = $MuzzleInShapeTester


func shoot():
	if not ray_cast_2d.is_colliding(): return
	
	if muzzle_in_shape_tester.get_overlapping_bodies().size() > 0: return
	
	var config = item_data.item_config as ItemBaseConfig
	var player = holder as Player
	
	var collision_point = ray_cast_2d.get_collision_point()
	var collision_normal = ray_cast_2d.get_collision_normal()
	
	var laser_shooter = (ResourceManager.get_resource("laser_shooter_for_gun") as PackedScene).instantiate() as LaserShooterForGun
	laser_shooter.sender = holder
	laser_shooter.attack = config.attack + player.player_data.get_attack()
	laser_shooter.critical_rate = config.critical_rate
	laser_shooter.critical_bonus = config.critical_bonus
	laser_shooter.knockback = config.knockback
	laser_shooter.hit_cam_shake_strength = config.attack_cam_shake_intensity
	laser_shooter.hit_cam_shake_duration = config.attack_cam_shake_duration
	laser_shooter.target_position = collision_point
	laser_shooter.target_dir = collision_normal
	
	player.level.bullets_parent.add_child(laser_shooter)
	laser_shooter.global_position = ray_cast_2d.global_position
	
